package com.lwbldy.modules.student.controller;

import com.lwbldy.common.tools.R;
import com.lwbldy.common.tools.PageUtils;
import com.lwbldy.common.tools.StringUtils;

import com.lwbldy.modules.student.domain.Refund;
import com.lwbldy.modules.student.service.RefundService;

import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
 * 退费记录 Controller
 * @author lwb
 * @email lwbldy@163.com
 * @date 2022-10-19 17:33:28
 */
@Controller
@Api(tags = "退费记录")
@RequestMapping("/student/refund")
public class RefundController {

    /**
     * Describe: 基础路径
     * */
    private static String MODULE_PATH = "student/refund/";


    @Autowired
    private RefundService refundService;

    @ApiOperation(value="获取列表视图")
    @GetMapping("/main")
    public String main(){
        return MODULE_PATH + "main";
    }


    @ApiOperation(value = "分页查询退费记录")
    @PostMapping("/list")
    @ResponseBody
    public R list(
            @RequestParam(value = "stuIdcard",required = false) String stuIdcard,
            @RequestParam(value = "stuName",required = false) String stuName,
            @RequestParam(value = "contacts",required = false) String contacts,
            @RequestParam(value = "phone",required = false) String phone,
            @RequestParam(value = "status",required = false) Integer status,
            @RequestParam(value = "page", defaultValue = "1") Integer page,
            @RequestParam(value = "limit", defaultValue = "15") Integer limit){
        PageHelper.startPage(page, limit);
        Map<String,Object> primaryMap = new HashMap<>();
        primaryMap.put("stuIdcard",stuIdcard);
        primaryMap.put("stuName",stuName);
        primaryMap.put("contacts",contacts);
        primaryMap.put("status",status);
        primaryMap.put("phone",phone);
        List<Refund> brandList = refundService.queryList(primaryMap);
        return PageUtils.restPage(brandList);
    }


    @ApiOperation(value = "获取新增视图")
    @GetMapping("add")
    public String add(ModelMap model){
        return MODULE_PATH + "add";
    }

    @ApiOperation(value = "保存")
    @PostMapping("save")
    @ResponseBody
    public R save(@RequestBody Refund refund){
        return R.resultRow(refundService.save(refund));
    }


    @ApiOperation(value = "获取修改视图")
    @GetMapping("edit")
    public String edit(ModelMap model, Integer id){
        model.put("refund",refundService.queryObject(id));
        return MODULE_PATH + "edit";
    }

    @ApiOperation(value = "修改信息")
    @PutMapping("update")
    @ResponseBody
    public R update(@RequestBody Refund refund){
        return R.resultRow(refundService.update(refund));
    }

    @ApiOperation(value = "根据ID删除")
    @DeleteMapping("remove/{id}")
    @ResponseBody
    public R remove(@PathVariable Integer id){
        int result = refundService.delete(id);
        return R.resultRow(result);
    }

    @DeleteMapping("removeBatch/{ids}")
    @ApiOperation(value="批量删除数据")
    @ResponseBody
    public R removeBatch(@PathVariable String ids){
        int result = refundService.deleteBatch(StringUtils.StringIdsToArr(ids));
        return R.resultRow(result);
    }

    @PostMapping("auditRefund")
    @ApiOperation(value="审核退费")
    @ResponseBody
    public R auditRefund(int id,int status){
        return refundService.auditRefund(id,status);
    }

}
